package prticemap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Map04 {
    public static void main(String[] args) {
        //创建HasMap集合，键是String学生对象，值是籍贯String,存储3个键值对象，遍历
        HashMap<Student,String>hashMap=new HashMap<>();
        Student student=new Student("xiaohei",22);
        Student student1=new Student("xiaoming",22);
        Student student2=new Student("dahei",24);
        Student student3=new Student("daming",21);
        hashMap.put(student,"江苏");
        hashMap.put(student1,"杭州");
        hashMap.put(student2,"上海");
        hashMap.put(student3,"四川");
        Set<Student> students = hashMap.keySet();
        for (Student student4 : students) {
            String s = hashMap.get(student4);
            System.out.println(student4+"-----"+s);
        }
        System.out.println("-------");
       Set<Map.Entry<Student, String>> entries = hashMap.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String s = entry.getValue();
            System.out.println(key+"---"+s);

hashMap.forEach((Student key1,String value1)->
        System.out.println(key1+value1));
        }




    }
}
